<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :advOptions="[]"
      :dictMap="dictMapAsync"
      :formOptions="formOptions"
      :outputQueryParams="queryParams"
      :queryParams="queryParams"
    ></Ht-search-form>

    <!--    <div class="page-label-block">-->
    <!--      <span class="color-block">|</span>-->
    <!--      <span class="page-label-name">-->
    <!--      租户管理-->
    <!--      </span>-->
    <!--    </div>-->

    <ht-table
      ref="dataTable"
      :dictMap="dictMap"
      :multi-select="false"
      :opButtonList="opButtonList"
      :queryParams="queryParams"
      :reqConfig="regConfig"
      :showSerialNumber="false"
      :tableBindColumns="tableBindColumns"
    >
      <template v-slot:operate>
        <el-table-column align="left" fixed="right" label="操作" width="50">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '审核',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      center
      :visible.sync="open"
      v-if="open"
      append-to-body
      width="1024px"
    >
      <el-form ref="detailForm" :model="detailForm" label-width="120px">
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>业务查询查复审核</span>
          </div>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="查询/查复流水号：" prop="id">
                <el-input v-model="detailForm.id" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="CPG日期" prop="vdate">
                <el-date-picker
                  v-model="detailForm.vdate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="系统编号" prop="sysCode">
                <el-select style="width: 100%" v-model="detailForm.sysCode" placeholder="系统编号" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.SYS_CODE_310_312"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="查询类型" prop="inqType">
                <el-select style="width: 100%" v-model="detailForm.inqType" placeholder="查询类型" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.QUERYTYPECODE"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="报文类型" prop="pkgNo">
                <el-input v-model="detailForm.pkgNo" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="币种" prop="curcd">
                <el-select style="width: 100%" v-model="detailForm.curcd" placeholder="币种" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.CURCD"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="金额" prop="amount">
                <ht-amount-input v-model="detailForm.amount" placeholder="金额" :disable="true"></ht-amount-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>查询信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="查询内容" prop="inqContent">
                <el-input type="textarea" v-model="detailForm.inqContent" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>查复信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="查复内容" prop="rspContent">
                <el-input type="textarea" v-model="detailForm.rspContent" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>

        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>原业务信息</span>
          </div>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原报文标识号" prop="oriPkgId">
                <el-input v-model="detailForm.oriPkgId" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="原发起参与机构" prop="oriSender">
                <el-input v-model="detailForm.oriSender" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原发起参与机构名称" prop="oriSenderName">
                <el-input v-model="detailForm.oriSenderName" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="原业务类型" prop="oriBizType">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.oriBizType === null || detailForm.oriBizType === undefined
                      ? ''
                      : detailForm.oriBizType + '-' + detailForm.oriBizTypeDesc
                  "
                  placeholder="原业务类型"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="原明细标识号" prop="oriDtlNo">
                <el-input v-model="detailForm.oriDtlNo" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="原交易流水/批次号" prop="oriId">
                <el-input v-model="detailForm.oriId" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="录入操作员" prop="mdTlrno">
                <el-input v-model="detailForm.mdTlrno" :disabled="true" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="录入时间" prop="mdTime">
                <el-date-picker
                  style="width: 100%"
                  v-model="detailForm.mdTime"
                  value-format="yyyyMMddHHmmss"
                  type="datetime"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="审核附言" prop="audRemarks">
                <el-input type="textarea" v-model="detailForm.audRemarks" maxlength="128" show-word-limit/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>

      <div slot="footer" align="center" class="dialog-footer">
        <el-button type="primary" @click="approve" v-loading.fullscreen.lock="loading">审 核</el-button>
        <el-button type="primary" @click="reject" v-loading.fullscreen.lock="loading">拒 绝</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  apiUrlConfigApprove,
  inquiryResponseApproveApprove,
  inquiryResponseApproveDetail,
  inquiryResponseApproveReject,
} from "@/api/cnaps/ccms/315";
import { listPageMixin } from "@/libs/listPageMixin";
import HtAmountInput from "@/views/components/HtAmountInput";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";
export default {
  name: "InquiryResponseApprove",
  mixins: [listPageMixin],
  components: { HtAmountInput },
  data() {
    let self = this;
    return {
      // 查询参数
      queryParams: {
        vdate: undefined,
        vdate2: undefined,
        workdate: undefined,
        workdate2: undefined,
        idSeqNo: undefined,
      },

      loading: false,
      // 搜索
      formOptions: [],
      //
      searchFormDictList: ["SYS_CODE_310_312", "PKG_TYPE", "QUERYTYPECODE", "CURCD"],
      // 列信息
      regConfig: apiUrlConfigApprove,

      tableBindColumns: [
        { prop: "id", label: "查询/查复流水号", width: "180" },
        { prop: "vdate", label: "CPG日期", type: "date" },
        { prop: "workdate", label: "工作日期", type: "date" },
        { prop: "sysCode", label: "系统编号", dictCode: "SYS_CODE_310_312", width: "180" },
        { prop: "pkgNo", label: "报文类型", dictCode: "PKG_TYPE" },
        {
          prop: "oriMsgType",
          label: "原报文类型",
          width: "240",
          formatter(row, text, index) {
            return row["oriMsgType"] + "-" + row["oriMsgTypeDesc"];
          },
        },
        {
          prop: "amount",
          label: "金额",
          width: "120",
          type: "price",
        },
        { prop: "mdTlrno", label: "录入操作员", sortable: false },
        { prop: "mdTime", label: "录入时间", type: "date", width: "180" },
      ],
      dictMapAsync: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      detailForm: {
        pkgNo: undefined,
        pkgNoDesc: undefined,
      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,
      rules: {},
    };
  },
  mounted() {
    const formOptions = [
      // 普通搜索

      {
        type: "dates",
        nameObj: {
          startTimeName: "vdate",
          endTimeName: "vdate2",
        },
        defaultAttr: {
          size: "small",
          label: "CPG日期",
          placeholder: ["请输入CPG开始日期", "请输入CPG结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      {
        type: "dates",
        nameObj: {
          startTimeName: "workdate",
          endTimeName: "workdate2",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作开始日期", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      {
        type: "input",
        prop: "idSeqNo",
        defaultAttr: {
          size: "small",
          label: "查询/查复流水号",
          placeholder: "请输入查询/查复流水号",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "业务查询查复审核明细";
      inquiryResponseApproveDetail(row.id).then((response) => {
        this.detailForm = response.result;
        this.open = true;
      });
    },
    //点击审核按钮
    approve: function () {
      (this.loading = true),
        inquiryResponseApproveApprove(this.detailForm)
          .then((response) => {
            this.msgSuccess("审核成功");
            this.open = false;
            this.loading = false;
            this.$nextTick(() => {
              this.$refs.dataTable.doQuery(true);
            });
          })
          .catch((err) => {
            this.loading = false;
          });
    },

    //点击拒绝按钮
    reject() {
      this.loading = true;
      inquiryResponseApproveReject(this.detailForm)
        .then((response) => {
          this.msgSuccess("拒绝成功");
          this.open = false;
          this.loading = false;
          this.$nextTick(() => {
            this.$refs.dataTable.doQuery(true);
          });
        })
        .catch((err) => {
          this.loading = false;
        });
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
